#define _CRT_SECURE_NO_WARNINGS 1

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    bool checkSymmetricTree(TreeNode* root) {
        if (root == nullptr) return true;
        return check(root->left, root->right);
    }
    bool check(TreeNode* left, TreeNode* right)
    {
        if (left == nullptr && right != nullptr) return false;
        if (left != nullptr && right == nullptr) return false;
        if (left == nullptr && right == nullptr) return true;
        if (left->val != right->val) return false;

        return check(left->left, right->right) && check(left->right, right->left);
    }
};


/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    int sumNumbers(TreeNode* root) {
        return sum(root, 0);
    }
    int sum(TreeNode* root, int presum)
    {
        presum = presum * 10 + root->val;
        if (root->left == nullptr && root->right == nullptr) return presum;

        int ret = 0;
        if (root->left) ret += sum(root->left, presum);
        if (root->right) ret += sum(root->right, presum);
        return ret;
    }
};


class Solution {
public:
    bool isUnique(string astr) {
        set<char> m;
        for (int i = 0; i < astr.size(); i++)
        {
            m.insert(astr[i]);
        }
        return m.size() == astr.size() ? true : false;
    }
};